﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using UnityEngine;
using System.Collections;

namespace Galaxy
{
    public class GalaxyParamPoolOnwer
    {
        public ParamPool Pool;
        public GalaxyParamPoolOnwer()
        {
        }
        public void SetParamPool(ParamPool pool)
        {
            if (pool == null)
                return;

            Pool = pool;

            RegistryParamChangeHandle(ParamDataChangeHandle);
        }
        public void UpdataFromPacketBuffer(byte[] buffer,bool bFinish = true, bool bInit = false)
        {
            if (Pool == null)
                return;
            if (buffer.Length <= 0)
                return;
			
            Pool.Read(buffer);

            if (bInit && bFinish)
            {
                ParamDataFinish();
            }
        }
        protected virtual void ParamDataChangeHandle(string name, ParamPool pool, object oldVal, object newVal)
        {

        }
        public virtual void ParamDataFinish(){ }
        public void RegistryParamChangeHandle(ParamPool.HandleParamChange handle)
        {
            if (handle == null)
                return;
            Pool.ParamChangeHandle += handle;
        }
        public void UnregistryParamChangeHandle(ParamPool.HandleParamChange handle)
        {
            if (handle == null)
                return;
            Pool.ParamChangeHandle -= handle;
        }
        public int GetParamType()
        {
            if (null == Pool)
                return -1;
            return Pool.ParamID;
        }

        public int GetParamDataID()
        {
            if (null == Pool)
                return 0;
            return Pool.DataID;
        }
    }

   

}
